<?php

include  __DIR__ . '/../vendor/autoload.php';

use IMOcean\Utils\CoroutineCoat;

CoroutineCoat::Run(function () {
    CoroutineCoat::Go(function () {
        $server = new \Swoole\Coroutine\Http\Server('127.0.0.1', 9502, false);

        $server->handle('/', function ($request, $response) {
            $response->end("<h1>Index</h1>");
        });

        $server->handle('/test', function ($request, $response) {
            $response->end("<h1>Test</h1>");
        });

        $server->handle('/stop', function ($request, $response) use ($server) {
            $response->end("<h1>Stop</h1>");
            $server->shutdown();
        });

        $server->start();
    });
});

